﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
using SuperPongControl;

public partial class SuperPong : Game
{

    void handleKeyInput()
    {

        if (gameState == SuperPongControl.Types.GameState.GAME_RUNNING)
        {

            List<SuperPongControl.Types.InputHandlerResultGameRuntime> moves = inputHandler.handleKeyInputGameRunning(Players[1].isCPU, Paused);

            foreach (SuperPongControl.Types.InputHandlerResultGameRuntime move in moves)
            {
                switch (move)
                {
                    case SuperPongControl.Types.InputHandlerResultGameRuntime.PlayerZeroUp:
                        this.Players[0].Up(this.gameTime);
                        break;
                    case SuperPongControl.Types.InputHandlerResultGameRuntime.PlayerZeroDown:
                        this.Players[0].Down(this.gameTime);
                        break;
                    case SuperPongControl.Types.InputHandlerResultGameRuntime.PlayerOneUp:
                        this.Players[1].Up(this.gameTime);
                        break;
                    case SuperPongControl.Types.InputHandlerResultGameRuntime.PlayerOneDown:
                        this.Players[1].Down(this.gameTime);
                        break;
                    case SuperPongControl.Types.InputHandlerResultGameRuntime.TogglePause:
                        TogglePause();
                        break;
                    case SuperPongControl.Types.InputHandlerResultGameRuntime.GoToMainMenu:
                        gameState = SuperPongControl.Types.GameState.MAIN_MENU;
                        break;
                }
            }

        }
        /* Input handling for the Main Menu */
        else if (gameState == SuperPongControl.Types.GameState.MAIN_MENU)
        {
            Dictionary<Types.InputHandlerResultMainMenu, Object> moves = inputHandler.handleKeyInputMainMenu();

            foreach (KeyValuePair<Types.InputHandlerResultMainMenu, Object> move in moves)
            {
                switch (move.Key)
                {
                    case Types.InputHandlerResultMainMenu.ProcessMouseMove:
                        MainMenu.ProcessMouseMove((Vector2)move.Value);
                        break;
                    case Types.InputHandlerResultMainMenu.MainMenuUp:
                        MainMenu.Up();
                        break;
                    case Types.InputHandlerResultMainMenu.MainMenuDown:
                        MainMenu.Down();
                        break;
                    case Types.InputHandlerResultMainMenu.MainMenuProcessMouseClick:
                        handleMainMenu(MainMenu.ProcessMouseClick((Vector2)move.Value));
                        break;
                    case Types.InputHandlerResultMainMenu.MainMenuSelect:
                        handleMainMenu(MainMenu.Select());
                        break;
                }
            }
        }
        /* Input handling for the Instructions screen and the Credits screen */
        else if (gameState == SuperPongControl.Types.GameState.INSTRUCTIONS || gameState == SuperPongControl.Types.GameState.CREDITS)
        {
            Dictionary<Types.InputHandlerResultInsCred, Object> moves = inputHandler.handleKeyInputInsCred();

            foreach (KeyValuePair<Types.InputHandlerResultInsCred, Object> move in moves)
            {
                switch (move.Key)
                {
                    case Types.InputHandlerResultInsCred.BackMenuProcessMouseClick:
                        handleBackMenu(BackMenu.ProcessMouseClick((Vector2)move.Value));
                        break;
                    case Types.InputHandlerResultInsCred.BackMenuSelect:
                        handleBackMenu(BackMenu.Select());
                        break;
                }
            }
        }
        /* Input handling for number of player selection */
        else if (gameState == SuperPongControl.Types.GameState.NUM_PLAYER_SCREEN)
        {
            Dictionary<Types.InputHandlerResultNumPlayers, Object> moves = inputHandler.handleKeyInputNumPlayers();

            foreach (KeyValuePair<Types.InputHandlerResultNumPlayers, Object> move in moves)
            {
                switch (move.Key)
                {
                    case Types.InputHandlerResultNumPlayers.NumPlayersMenuUp:
                        NumPlayersMenu.Up();
                        break;
                    case Types.InputHandlerResultNumPlayers.NumPlayersMenuDown:
                        NumPlayersMenu.Down();
                        break;
                    case Types.InputHandlerResultNumPlayers.NumPlayersMenuProcessMouseMove:
                        NumPlayersMenu.ProcessMouseMove((Vector2)move.Value);
                        break;
                    case Types.InputHandlerResultNumPlayers.BackMenuProcessMouseClick:
                        handleBackMenu(BackMenu.ProcessMouseClick((Vector2)move.Value));
                        break;
                    case Types.InputHandlerResultNumPlayers.NumPlayersMenuProcessMouseClick:
                        handleNumPlayersMenu(NumPlayersMenu.ProcessMouseClick((Vector2)move.Value));
                        break;
                    case Types.InputHandlerResultNumPlayers.NumPlayersMenuSelect:
                        handleNumPlayersMenu(NumPlayersMenu.Select());
                        break;
                    case Types.InputHandlerResultNumPlayers.BackMenuSelect:
                        handleBackMenu(BackMenu.Select());
                        break;
                }
            }
        }
        /* Input handling for lives selection */
        else if (gameState == SuperPongControl.Types.GameState.LIFE_SELECTION_SCREEN)
        {
            Dictionary<Types.InputHandlerResultLifeSelect, Object> moves = inputHandler.handleKeyInputLifeSelect();

            foreach (KeyValuePair<Types.InputHandlerResultLifeSelect, Object> move in moves)
            {
                switch (move.Key)
                {
                    case Types.InputHandlerResultLifeSelect.LifeSelectMenuUp:
                        LifeSelectMenu.Up();
                        break;
                    case Types.InputHandlerResultLifeSelect.LifeSelectMenuDown:
                        LifeSelectMenu.Down();
                        break;
                    case Types.InputHandlerResultLifeSelect.LifeSelectMenuProcessMouseMove:
                        LifeSelectMenu.ProcessMouseMove((Vector2)move.Value);
                        break;
                    case Types.InputHandlerResultLifeSelect.BackMenuProcessMouseClick:
                        handleBackMenu3(BackMenu.ProcessMouseClick((Vector2)move.Value));
                        break;
                    case Types.InputHandlerResultLifeSelect.LifeSelectMenuProcessMouseClick:
                        handleLifeSelectMenu(LifeSelectMenu.ProcessMouseClick((Vector2)move.Value));
                        break;
                    case Types.InputHandlerResultLifeSelect.LifeSelectMenuSelect:
                        handleLifeSelectMenu(LifeSelectMenu.Select());
                        break;
                    case Types.InputHandlerResultLifeSelect.BackMenuSelect:
                        handleBackMenu3(BackMenu.Select());
                        break;
                }
            }
           
        }
        /* Input handling for difficulty selection */
        else if (gameState == SuperPongControl.Types.GameState.DIFFICULTY_SCREEN)
        {
            Dictionary<Types.InputHandlerResultDiff, Object> moves = inputHandler.handleKeyInputDiff();

            foreach (KeyValuePair<Types.InputHandlerResultDiff, Object> move in moves)
            {
                switch (move.Key)
                {
                    case Types.InputHandlerResultDiff.DiffMenuUp:
                        DifficultyMenu.Up();
                        break;
                    case Types.InputHandlerResultDiff.DiffMenuDown:
                        DifficultyMenu.Down();
                        break;
                    case Types.InputHandlerResultDiff.DiffMenuProcessMouseMove:
                        DifficultyMenu.ProcessMouseMove((Vector2)move.Value);
                        break;
                    case Types.InputHandlerResultDiff.BackMenuProcessMouseClick:
                        handleBackMenu3(BackMenu.ProcessMouseClick((Vector2)move.Value));
                        break;
                    case Types.InputHandlerResultDiff.DiffMenuProcessMouseClick:
                        handleDifficultyMenu(DifficultyMenu.ProcessMouseClick((Vector2)move.Value));
                        break;
                    case Types.InputHandlerResultDiff.DiffMenuSelect:
                        handleDifficultyMenu(DifficultyMenu.Select());
                        break;
                    case Types.InputHandlerResultDiff.BackMenuSelect:
                        handleBackMenu3(BackMenu.Select());
                        break;
                }
            }
        }//
            else if (gameState == SuperPongControl.Types.GameState.GAME_END)
            {
                Dictionary<Types.InputHandlerResultEnd, Object> moves = inputHandler.handleKeyInputEnd();

                foreach (KeyValuePair<Types.InputHandlerResultEnd, Object> move in moves)
                {
                    switch (move.Key)
                    {
                        case Types.InputHandlerResultEnd.EndMenuUp:
                            GameEndMenu.Up();
                            break;
                        case Types.InputHandlerResultEnd.EndMenuDown:
                            GameEndMenu.Down();
                            break;
                        case Types.InputHandlerResultEnd.EndMenuProcessMouseMove:
                            GameEndMenu.ProcessMouseMove((Vector2)move.Value);
                            break;
                        case Types.InputHandlerResultEnd.EndMenuProcessMouseClick:
                            handleGameEndMenu(GameEndMenu.ProcessMouseClick((Vector2)move.Value));
                            break;
                        case Types.InputHandlerResultEnd.EndMenuSelect:
                            handleGameEndMenu(GameEndMenu.Select());
                            break;
                        case Types.InputHandlerResultEnd.BackMenuSelect:
                            gameState = SuperPongControl.Types.GameState.MAIN_MENU;
                            break;
                    }
                }
            }
        }
    }
